#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<climits>
using namespace std;
const int N = 2e5 + 10;
typedef long long LL;
LL a[N];
int n;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	int sum = 0, ret = INT_MIN;
	for (int i = 1; i <= n; i++)
	{
		sum += a[i];
		ret = max(sum, ret);
		if (sum < 0) sum = 0;
	}
	cout << ret << endl;
	return 0;
}